#coding=utf-8
#Boa:FramePanel:PanelCashFlow

import wx
from MyListCtrl import MySimpleListCtrl

from product import CDataCashFlow
import kit

[wxID_PANELCASHFLOW, wxID_PANELCASHFLOWBTNDEL, wxID_PANELCASHFLOWBTNMODIFY, 
 wxID_PANELCASHFLOWBTNRECALC, wxID_PANELCASHFLOWBTNSAVE, 
 wxID_PANELCASHFLOWDATEEND, wxID_PANELCASHFLOWDATESTART, 
 wxID_PANELCASHFLOWSTATICTEXT1, wxID_PANELCASHFLOWSTATICTEXT10, 
 wxID_PANELCASHFLOWSTATICTEXT11, wxID_PANELCASHFLOWSTATICTEXT12, 
 wxID_PANELCASHFLOWSTATICTEXT13, wxID_PANELCASHFLOWSTATICTEXT14, 
 wxID_PANELCASHFLOWSTATICTEXT15, wxID_PANELCASHFLOWSTATICTEXT16, 
 wxID_PANELCASHFLOWSTATICTEXT17, wxID_PANELCASHFLOWSTATICTEXT18, 
 wxID_PANELCASHFLOWSTATICTEXT19, wxID_PANELCASHFLOWSTATICTEXT2, 
 wxID_PANELCASHFLOWSTATICTEXT20, wxID_PANELCASHFLOWSTATICTEXT21, 
 wxID_PANELCASHFLOWSTATICTEXT3, wxID_PANELCASHFLOWSTATICTEXT4, 
 wxID_PANELCASHFLOWSTATICTEXT5, wxID_PANELCASHFLOWSTATICTEXT6, 
 wxID_PANELCASHFLOWSTATICTEXT7, wxID_PANELCASHFLOWSTATICTEXT8, 
 wxID_PANELCASHFLOWSTATICTEXT9, wxID_PANELCASHFLOWTCCASHFLOWFINANCE, 
 wxID_PANELCASHFLOWTCCASHFLOWINVEST, wxID_PANELCASHFLOWTCCASHFLOWOPERATING, 
 wxID_PANELCASHFLOWTCCASHFROMOTHER, wxID_PANELCASHFLOWTCCASHFROMSALE, 
 wxID_PANELCASHFLOWTCCASHINSUBTOTAL, wxID_PANELCASHFLOWTCCASHOTHEROUT, 
 wxID_PANELCASHFLOWTCCASHOUTSUBTOTAL, wxID_PANELCASHFLOWTCCASHPUR, 
 wxID_PANELCASHFLOWTCCASHTOEMPLOYEE, wxID_PANELCASHFLOWTCINVESTINSUBTOTAL, 
 wxID_PANELCASHFLOWTCINVESTOUTSUBTOTAL, wxID_PANELCASHFLOWTCMEMO, 
 wxID_PANELCASHFLOWTCNETFLOWINVEST, wxID_PANELCASHFLOWTCNETFLOWOPERATING, 
 wxID_PANELCASHFLOWTCPAIDFORASSET, wxID_PANELCASHFLOWTCPAIDFORINVEST, 
 wxID_PANELCASHFLOWTCRETURNFROMASSETS, wxID_PANELCASHFLOWTCRETURNFROMINVEST, 
] = [wx.NewId() for _init_ctrls in range(47)]

class PanelCashFlow(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELCASHFLOW, name=u'PanelCashFlow',
              parent=prnt, pos=wx.Point(792, 196), size=wx.Size(1026, 767),
              style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(1010, 729))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.staticText2 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT2,
              label=u'\u8d77\u6b62\u65e5\u671f', name='staticText2',
              parent=self, pos=wx.Point(56, 56), size=wx.Size(68, 16), style=0)

        self.staticText1 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT1,
              label=u'\u73b0\u91d1\u6d41\u91cf\u8868', name='staticText1',
              parent=self, pos=wx.Point(176, 16), size=wx.Size(85, 16),
              style=0)

        self.dateStart = wx.DatePickerCtrl(id=wxID_PANELCASHFLOWDATESTART,
              name=u'dateStart', parent=self, pos=wx.Point(144, 48),
              size=wx.Size(121, 24), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

        self.staticText3 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT3,
              label=u'\u81f3', name='staticText3', parent=self,
              pos=wx.Point(272, 56), size=wx.Size(17, 16), style=0)

        self.dateEnd = wx.DatePickerCtrl(id=wxID_PANELCASHFLOWDATEEND,
              name=u'dateEnd', parent=self, pos=wx.Point(304, 48),
              size=wx.Size(121, 24), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)

        self.btnRecalc = wx.Button(id=wxID_PANELCASHFLOWBTNRECALC,
              label=u'\u8ba1\u7b97', name=u'btnRecalc', parent=self,
              pos=wx.Point(432, 48), size=wx.Size(93, 26), style=0)
        self.btnRecalc.Bind(wx.EVT_BUTTON, self.OnBtnRecalcButton,
              id=wxID_PANELCASHFLOWBTNRECALC)

        self.btnSave = wx.Button(id=wxID_PANELCASHFLOWBTNSAVE,
              label=u'\u4fdd\u5b58\u65b0\u8868', name=u'btnSave', parent=self,
              pos=wx.Point(752, 48), size=wx.Size(93, 26), style=0)
        self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton,
              id=wxID_PANELCASHFLOWBTNSAVE)

        self.btnDel = wx.Button(id=wxID_PANELCASHFLOWBTNDEL,
              label=u'\u5220\u9664', name=u'btnDel', parent=self,
              pos=wx.Point(864, 48), size=wx.Size(93, 26), style=0)
        self.btnDel.Bind(wx.EVT_BUTTON, self.OnBtnDelButton,
              id=wxID_PANELCASHFLOWBTNDEL)

        self.staticText4 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT4,
              label=u'\u4e00\u3001\u7ecf\u8425\u73b0\u91d1\u6d41\u91cf',
              name='staticText4', parent=self, pos=wx.Point(56, 88),
              size=wx.Size(136, 16), style=0)

        self.tcCashFlowOperating = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHFLOWOPERATING,
              name=u'tcCashFlowOperating', parent=self, pos=wx.Point(224, 88),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashFlowOperating.Enable(False)

        self.tcCashFromSale = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHFROMSALE,
              name=u'tcCashFromSale', parent=self, pos=wx.Point(224, 120),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashFromSale.Bind(wx.EVT_TEXT, self.OnTcCashFromSaleText,
              id=wxID_PANELCASHFLOWTCCASHFROMSALE)

        self.staticText5 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT5,
              label=u'\u9500\u552e/\u52b3\u52a1\u73b0\u91d1',
              name='staticText5', parent=self, pos=wx.Point(104, 120),
              size=wx.Size(100, 18), style=0)
        self.staticText5.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.staticText6 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT6,
              label=u'\u5176\u4ed6\u73b0\u91d1', name='staticText6',
              parent=self, pos=wx.Point(104, 152), size=wx.Size(64, 18),
              style=0)
        self.staticText6.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.tcCashFromOther = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHFROMOTHER,
              name=u'tcCashFromOther', parent=self, pos=wx.Point(224, 152),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashFromOther.SetBackgroundColour(wx.Colour(186, 255, 117))
        self.tcCashFromOther.Bind(wx.EVT_TEXT, self.OnTcCashFromOtherText,
              id=wxID_PANELCASHFLOWTCCASHFROMOTHER)

        self.tcCashInSubtotal = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHINSUBTOTAL,
              name=u'tcCashInSubtotal', parent=self, pos=wx.Point(224, 184),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashInSubtotal.Enable(False)
        self.tcCashInSubtotal.Bind(wx.EVT_TEXT, self.OnTcCashInSubtotalText,
              id=wxID_PANELCASHFLOWTCCASHINSUBTOTAL)

        self.staticText7 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT7,
              label=u'\u6d41\u5165\u73b0\u91d1\u5c0f\u8ba1', name='staticText7',
              parent=self, pos=wx.Point(88, 192), size=wx.Size(102, 16),
              style=0)

        self.staticText8 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT8,
              label=u'\u91c7\u8d2d\u652f\u4ed8\u73b0\u91d1', name='staticText8',
              parent=self, pos=wx.Point(104, 224), size=wx.Size(96, 18),
              style=0)
        self.staticText8.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.tcCashPur = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHPUR,
              name=u'tcCashPur', parent=self, pos=wx.Point(224, 216),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashPur.Bind(wx.EVT_TEXT, self.OnTcCashPurText,
              id=wxID_PANELCASHFLOWTCCASHPUR)

        self.tcCashToEmployee = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHTOEMPLOYEE,
              name=u'tcCashToEmployee', parent=self, pos=wx.Point(224, 248),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashToEmployee.Bind(wx.EVT_TEXT, self.OnTcCashToEmployeeText,
              id=wxID_PANELCASHFLOWTCCASHTOEMPLOYEE)

        self.staticText9 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT9,
              label=u'\u5458\u5de5\u73b0\u91d1', name='staticText9',
              parent=self, pos=wx.Point(104, 256), size=wx.Size(64, 18),
              style=0)
        self.staticText9.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.staticText10 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT10,
              label=u'\u5176\u4ed6\u7ecf\u8425\u652f\u4ed8',
              name='staticText10', parent=self, pos=wx.Point(104, 288),
              size=wx.Size(96, 18), style=0)
        self.staticText10.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.tcCashOtherOut = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHOTHEROUT,
              name=u'tcCashOtherOut', parent=self, pos=wx.Point(224, 280),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashOtherOut.Bind(wx.EVT_TEXT, self.OnTcCashOtherOutText,
              id=wxID_PANELCASHFLOWTCCASHOTHEROUT)

        self.tcCashOutSubtotal = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHOUTSUBTOTAL,
              name=u'tcCashOutSubtotal', parent=self, pos=wx.Point(224, 312),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashOutSubtotal.Enable(False)
        self.tcCashOutSubtotal.Bind(wx.EVT_TEXT, self.OnTcCashOutSubtotalText,
              id=wxID_PANELCASHFLOWTCCASHOUTSUBTOTAL)

        self.staticText13 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT13,
              label=u'\u6d41\u51fa\u73b0\u91d1\u5c0f\u8ba1',
              name='staticText13', parent=self, pos=wx.Point(88, 320),
              size=wx.Size(102, 16), style=0)

        self.staticText14 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT14,
              label=u'\u7ecf\u8425\u73b0\u91d1\u6d41\u51c0\u989d',
              name='staticText14', parent=self, pos=wx.Point(88, 352),
              size=wx.Size(119, 16), style=0)

        self.tcNetFlowOperating = wx.TextCtrl(id=wxID_PANELCASHFLOWTCNETFLOWOPERATING,
              name=u'tcNetFlowOperating', parent=self, pos=wx.Point(224, 344),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcNetFlowOperating.Enable(False)

        self.tcCashFlowFinance = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHFLOWFINANCE,
              name=u'tcCashFlowFinance', parent=self, pos=wx.Point(224, 632),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')

        self.staticText11 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT11,
              label=u'\u4e09\u3001\u878d\u8d44\u73b0\u91d1\u6d41\u91cf',
              name='staticText11', parent=self, pos=wx.Point(72, 640),
              size=wx.Size(136, 16), style=0)

        self.staticText12 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT12,
              label=u'\u8d2d\u7f6e\u8d44\u4ea7\u652f\u4ed8',
              name='staticText12', parent=self, pos=wx.Point(112, 512),
              size=wx.Size(96, 18), style=0)
        self.staticText12.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.tcPaidForAsset = wx.TextCtrl(id=wxID_PANELCASHFLOWTCPAIDFORASSET,
              name=u'tcPaidForAsset', parent=self, pos=wx.Point(224, 504),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcPaidForAsset.Bind(wx.EVT_TEXT, self.OnTcPaidForAssetText,
              id=wxID_PANELCASHFLOWTCPAIDFORASSET)

        self.tcPaidForInvest = wx.TextCtrl(id=wxID_PANELCASHFLOWTCPAIDFORINVEST,
              name=u'tcPaidForInvest', parent=self, pos=wx.Point(224, 536),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcPaidForInvest.Bind(wx.EVT_TEXT, self.OnTcPaidForInvestText,
              id=wxID_PANELCASHFLOWTCPAIDFORINVEST)

        self.staticText15 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT15,
              label=u'\u5176\u4ed6\u6295\u8d44\u652f\u4ed8',
              name='staticText15', parent=self, pos=wx.Point(112, 544),
              size=wx.Size(96, 18), style=0)
        self.staticText15.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.staticText16 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT16,
              label=u'\u6295\u8d44\u73b0\u91d1\u6d41\u51c0\u989d',
              name='staticText16', parent=self, pos=wx.Point(96, 608),
              size=wx.Size(119, 16), style=0)

        self.tcNetFlowInvest = wx.TextCtrl(id=wxID_PANELCASHFLOWTCNETFLOWINVEST,
              name=u'tcNetFlowInvest', parent=self, pos=wx.Point(224, 600),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcNetFlowInvest.Enable(False)

        self.staticText17 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT17,
              label=u'\u5904\u7f6e\u8d44\u4ea7\u6536\u56de',
              name='staticText17', parent=self, pos=wx.Point(112, 416),
              size=wx.Size(96, 18), style=0)
        self.staticText17.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.tcReturnFromAssets = wx.TextCtrl(id=wxID_PANELCASHFLOWTCRETURNFROMASSETS,
              name=u'tcReturnFromAssets', parent=self, pos=wx.Point(224, 408),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcReturnFromAssets.Bind(wx.EVT_TEXT, self.OnTcReturnFromAssetsText,
              id=wxID_PANELCASHFLOWTCRETURNFROMASSETS)

        self.tcReturnFromInvest = wx.TextCtrl(id=wxID_PANELCASHFLOWTCRETURNFROMINVEST,
              name=u'tcReturnFromInvest', parent=self, pos=wx.Point(224, 440),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcReturnFromInvest.Bind(wx.EVT_TEXT, self.OnTcReturnFromInvestText,
              id=wxID_PANELCASHFLOWTCRETURNFROMINVEST)

        self.staticText18 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT18,
              label=u'\u5176\u4ed6\u6295\u8d44\u6536\u56de',
              name='staticText18', parent=self, pos=wx.Point(112, 448),
              size=wx.Size(96, 18), style=0)
        self.staticText18.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u''))

        self.staticText19 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT19,
              label=u'\u6295\u8d44\u6d41\u5165\u5c0f\u8ba1',
              name='staticText19', parent=self, pos=wx.Point(96, 480),
              size=wx.Size(102, 16), style=0)

        self.tcInvestInSubtotal = wx.TextCtrl(id=wxID_PANELCASHFLOWTCINVESTINSUBTOTAL,
              name=u'tcInvestInSubtotal', parent=self, pos=wx.Point(224, 472),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcInvestInSubtotal.Enable(False)
        self.tcInvestInSubtotal.Bind(wx.EVT_TEXT, self.OnTcInvestInSubtotalText,
              id=wxID_PANELCASHFLOWTCINVESTINSUBTOTAL)

        self.staticText20 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT20,
              label=u'\u6295\u8d44\u6d41\u51fa\u5c0f\u8ba1',
              name='staticText20', parent=self, pos=wx.Point(96, 576),
              size=wx.Size(102, 16), style=0)

        self.tcInvestOutSubtotal = wx.TextCtrl(id=wxID_PANELCASHFLOWTCINVESTOUTSUBTOTAL,
              name=u'tcInvestOutSubtotal', parent=self, pos=wx.Point(224, 568),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcInvestOutSubtotal.Enable(False)
        self.tcInvestOutSubtotal.Bind(wx.EVT_TEXT,
              self.OnTcInvestOutSubtotalText,
              id=wxID_PANELCASHFLOWTCINVESTOUTSUBTOTAL)

        self.staticText21 = wx.StaticText(id=wxID_PANELCASHFLOWSTATICTEXT21,
              label=u'\u4e8c\u3001\u6295\u8d44\u73b0\u91d1\u6d41\u91cf',
              name='staticText21', parent=self, pos=wx.Point(64, 384),
              size=wx.Size(136, 16), style=0)

        self.tcCashFlowInvest = wx.TextCtrl(id=wxID_PANELCASHFLOWTCCASHFLOWINVEST,
              name=u'tcCashFlowInvest', parent=self, pos=wx.Point(224, 376),
              size=wx.Size(152, 26), style=wx.TE_RIGHT, value=u'')
        self.tcCashFlowInvest.Enable(False)

        self.tcMemo = wx.TextCtrl(id=wxID_PANELCASHFLOWTCMEMO, name=u'tcMemo',
              parent=self, pos=wx.Point(384, 88), size=wx.Size(216, 568),
              style=wx.TE_MULTILINE, value=u'')

        self.btnModify = wx.Button(id=wxID_PANELCASHFLOWBTNMODIFY,
              label=u'\u4fdd\u5b58\u4fee\u6539', name=u'btnModify', parent=self,
              pos=wx.Point(864, 16), size=wx.Size(93, 26), style=0)
        self.btnModify.Bind(wx.EVT_BUTTON, self.OnBtnModifyButton,
              id=wxID_PANELCASHFLOWBTNMODIFY)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.curObj = None

        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())

        cols = [(CDataCashFlow.fi_id, wx.LIST_FORMAT_LEFT, 110),
                (CDataCashFlow.fi_CashFlowOperating, wx.LIST_FORMAT_RIGHT, 110),
                (CDataCashFlow.fi_NetFlowOperating, wx.LIST_FORMAT_RIGHT, 110)]
                
       
        self.lc = MySimpleListCtrl(self, CDataCashFlow, cols)
        self.lc.Move(wx.Point(610, 88))
        self.lc.SetSize(wx.Size(360, 568))
        #self.lc.refresh()
        self.lc.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListItemSelected)

        self.btnModify.Enable(False)
        self.btnDel.Enable(False)
        
    def OnListItemSelected(self, event):
        item = self.lc.GetNextItem(-1, state = wx.LIST_STATE_SELECTED)
        if (item == -1):
            return

        self.curObj = CDataCashFlow.getData({"id":self.lc.GetItemText(item)})
        self.ShowData()

        self.btnModify.Enable(True)
        self.btnDel.Enable(True)

    def ShowData(self):
        obj = self.curObj
        
        date = obj.getValue(obj.fi_dateStart)
        #self.dateStart.SetValue(date)
        self.dateStart.SetValue(wx.DateTimeFromDMY(date.day, date.month-1, date.year,0,0,0))
        date = obj.getValue(obj.fi_dateEnd)
        #self.dateEnd.SetValue(date)
        self.dateEnd.SetValue(wx.DateTimeFromDMY(date.day, date.month-1, date.year,0,0,0))

        self.tcCashFlowOperating.SetValue("%.0f" %(obj.getValue(obj.fi_CashFlowOperating)))
        self.tcCashFromSale.SetValue("%.0f" %(obj.getValue(obj.fi_CashFromSale)))
        self.tcCashFromOther.SetValue("%.0f" %(obj.getValue(obj.fi_CashFromOther)))
        self.tcCashInSubtotal.SetValue("%.0f" %(obj.getValue(obj.fi_CashInSubtotal)))
        self.tcCashPur.SetValue("%.0f" %(obj.getValue(obj.fi_CashPur)))
        self.tcCashToEmployee.SetValue("%.0f" %(obj.getValue(obj.fi_CashToEmployee)))
        self.tcCashOtherOut.SetValue("%.0f" %(obj.getValue(obj.fi_CashOtherOut)))
        self.tcCashOutSubtotal.SetValue("%.0f" %(obj.getValue(obj.fi_CashOutSubtotal)))
        self.tcNetFlowOperating.SetValue("%.0f" %(obj.getValue(obj.fi_NetFlowOperating)))
        self.tcCashFlowInvest.SetValue("%.0f" %(obj.getValue(obj.fi_CashFlowInvest)))
        self.tcReturnFromAssets.SetValue("%.0f" %(obj.getValue(obj.fi_ReturnFromAssets)))
        self.tcReturnFromInvest.SetValue("%.0f" %(obj.getValue(obj.fi_ReturnFromInvest)))
        self.tcInvestInSubtotal.SetValue("%.0f" %(obj.getValue(obj.fi_InvestInSubtotal)))
        self.tcPaidForAsset.SetValue("%.0f" %(obj.getValue(obj.fi_PaidForAsset)))
        self.tcPaidForInvest.SetValue("%.0f" %(obj.getValue(obj.fi_PaidForInvest)))
        self.tcInvestOutSubtotal.SetValue("%.0f" %(obj.getValue(obj.fi_InvestOutSubtotal)))
        self.tcNetFlowInvest.SetValue("%.0f" %(obj.getValue(obj.fi_NetFlowInvest)))
        self.tcCashFlowFinance.SetValue("%.0f" %(obj.getValue(obj.fi_CashFlowFinance)))
        self.tcMemo.SetValue(obj.getValue(obj.fi_memo))

    def getData(self):

        data = {
            CDataCashFlow.fi_dateStart : kit.str2Date(self.dateStart.GetValue().Format('%Y-%m-%d')),
            CDataCashFlow.fi_dateEnd : kit.str2Date(self.dateEnd.GetValue().Format('%Y-%m-%d')),
            CDataCashFlow.fi_CashFlowOperating : kit.toFloatOrZero(self.tcCashFlowOperating.GetValue()),
            CDataCashFlow.fi_CashFromSale : kit.toFloatOrZero(self.tcCashFromSale.GetValue()),
            CDataCashFlow.fi_CashFromOther : kit.toFloatOrZero(self.tcCashFromOther.GetValue()),
            CDataCashFlow.fi_CashInSubtotal : kit.toFloatOrZero(self.tcCashInSubtotal.GetValue()),
            CDataCashFlow.fi_CashPur : kit.toFloatOrZero(self.tcCashPur.GetValue()),
            CDataCashFlow.fi_CashToEmployee : kit.toFloatOrZero(self.tcCashToEmployee.GetValue()),
            CDataCashFlow.fi_CashOtherOut : kit.toFloatOrZero(self.tcCashOtherOut.GetValue()),
            CDataCashFlow.fi_CashOutSubtotal : kit.toFloatOrZero(self.tcCashOutSubtotal.GetValue()),
            CDataCashFlow.fi_NetFlowOperating : kit.toFloatOrZero(self.tcNetFlowOperating.GetValue()),
            CDataCashFlow.fi_CashFlowInvest : kit.toFloatOrZero(self.tcCashFlowInvest.GetValue()),
            CDataCashFlow.fi_ReturnFromAssets : kit.toFloatOrZero(self.tcReturnFromAssets.GetValue()),
            CDataCashFlow.fi_ReturnFromInvest : kit.toFloatOrZero(self.tcReturnFromInvest.GetValue()),
            CDataCashFlow.fi_InvestInSubtotal : kit.toFloatOrZero(self.tcInvestInSubtotal.GetValue()),
            CDataCashFlow.fi_PaidForAsset : kit.toFloatOrZero(self.tcPaidForAsset.GetValue()),
            CDataCashFlow.fi_PaidForInvest : kit.toFloatOrZero(self.tcPaidForInvest.GetValue()),
            CDataCashFlow.fi_InvestOutSubtotal : kit.toFloatOrZero(self.tcInvestOutSubtotal.GetValue()),
            CDataCashFlow.fi_NetFlowInvest : kit.toFloatOrZero(self.tcNetFlowInvest.GetValue()),
            CDataCashFlow.fi_CashFlowFinance : kit.toFloatOrZero(self.tcCashFlowFinance.GetValue()),
            CDataCashFlow.fi_memo : self.tcMemo.GetValue(),
        }

        return data

    def OnBtnRecalcButton(self, event):
        ''' 全部重算 '''
        dateStart = self.dateStart.GetValue().Format('%Y-%m-%d')
        dateEnd = self.dateEnd.GetValue().Format('%Y-%m-%d')
        
        sales = CDataCashFlow.GetCashFromSale(dateStart, dateEnd)
        cost  = CDataCashFlow.GetCashToPur(dateStart, dateEnd)
        emp  = CDataCashFlow.GetCashForEmp(dateStart, dateEnd)
        expense = CDataCashFlow.GetCashOther(dateStart, dateEnd)
        
        self.tcCashFromSale.SetValue('%.0f' %(sales or 0))
        self.tcCashPur.SetValue('%.0f' %(cost or 0))
        self.tcCashToEmployee.SetValue('%.0f' %(emp or 0))
        self.tcCashOtherOut.SetValue('%.0f' %(expense or 0))

    def OnBtnSaveButton(self, event):
        #if self.curObj is None:
        #    return

        import datetime

        if (self.tcCashFlowOperating.GetValue() == ""):
            return
                
        dlg = wx.TextEntryDialog(self, u'输入表名',
                                u'输入表名',self.dateStart.GetValue().Format('%Y%m%d'),wx.OK|wx.CANCEL|wx.CENTRE)
        if dlg.ShowModal() != wx.ID_OK:
            return
        name = dlg.GetValue()
        
        data = self.getData()
        data[CDataCashFlow.fi_id] = name
        
        obj = CDataCashFlow.factory()
        obj.setMulFieldVal(data)
        obj.insert()
        self.curObj = obj

        self.lc.refresh()

    def OnBtnModifyButton(self, event):
        ''' 保存修改 '''
        if self.curObj is None:
            return
        
        dlg = wx.MessageDialog(self, u'是否覆盖原记录？',u'提示',
                                    wx.YES_NO|wx.ICON_QUESTION)
        if(dlg.ShowModal() == wx.ID_NO):
            return

        self.curObj.setMulFieldVal(self.getData())
        self.curObj.update()

    def OnBtnDelButton(self, event):
        ''' 删除选中记录 '''
        if self.curObj is not None:
            self.curObj.delete()
            self.lc.refresh()

    def RecalcCashFlowOperating(self):
        '''重算 经营现金流量'''

        CashInSubtotal = kit.toFloatOrZero(self.tcCashInSubtotal.GetValue())
        CashOutSubtotal = kit.toFloatOrZero(self.tcCashOutSubtotal.GetValue())

        CashFlowOperating = CashInSubtotal + CashOutSubtotal

        self.tcCashFlowOperating.SetValue('%.0f' %(CashFlowOperating))

    def RecalcNetFlowOperating(self):
        '''重算 经营净现金流量'''

        CashInSubtotal = kit.toFloatOrZero(self.tcCashInSubtotal.GetValue())
        CashOutSubtotal = kit.toFloatOrZero(self.tcCashOutSubtotal.GetValue())

        NetFlowOperating = CashInSubtotal - CashOutSubtotal

        self.tcNetFlowOperating.SetValue('%.0f' %(NetFlowOperating))

    def RecalcCashInSubtotal(self):
        '''重算 现金流入小计'''

        CashFromSale = kit.toFloatOrZero(self.tcCashFromSale.GetValue())
        CashFromOther = kit.toFloatOrZero(self.tcCashFromOther.GetValue())

        CashInSubtotal = CashFromSale + CashFromOther

        self.tcCashInSubtotal.SetValue('%.0f' %(CashInSubtotal))

    def RecalcCashOutSubtotal(self):
        '''重算 现金流出小计'''

        CashPur = kit.toFloatOrZero(self.tcCashPur.GetValue())
        CashToEmployee = kit.toFloatOrZero(self.tcCashToEmployee.GetValue())
        CashOtherOut = kit.toFloatOrZero(self.tcCashOtherOut.GetValue())

        CashOutSubtotal = CashPur + CashToEmployee + CashOtherOut

        self.tcCashOutSubtotal.SetValue('%.0f' %(CashOutSubtotal))
    

    def OnTcCashFromSaleText(self, event):
        self.RecalcCashInSubtotal()

    def OnTcCashFromOtherText(self, event):
        self.RecalcCashOutSubtotal()

    def OnTcCashInSubtotalText(self, event):
        self.RecalcNetFlowOperating()
        self.RecalcCashFlowOperating()

    def OnTcCashPurText(self, event):
        self.RecalcCashOutSubtotal()

    def OnTcCashToEmployeeText(self, event):
        self.RecalcCashOutSubtotal()

    def OnTcCashOtherOutText(self, event):
        self.RecalcCashOutSubtotal()

    def OnTcCashOutSubtotalText(self, event):
        self.RecalcNetFlowOperating()
        self.RecalcCashFlowOperating()

    def RecalcCashFlowInvest(self):
        '''重算 投资现金流量'''

        InvestInSubtotal = kit.toFloatOrZero(self.tcInvestInSubtotal.GetValue())
        InvestOutSubtotal = kit.toFloatOrZero(self.tcInvestOutSubtotal.GetValue())

        CashFlowInvest = InvestInSubtotal + InvestOutSubtotal

        self.tcCashFlowInvest.SetValue('%.0f' %(CashFlowInvest))

    def RecalcNetFlowInvest(self):
        '''重算 投资净现金流量'''

        InvestInSubtotal = kit.toFloatOrZero(self.tcInvestInSubtotal.GetValue())
        InvestOutSubtotal = kit.toFloatOrZero(self.tcInvestOutSubtotal.GetValue())

        NetFlowInvest = InvestInSubtotal - InvestOutSubtotal

        self.tcNetFlowInvest.SetValue('%.0f' %(NetFlowInvest))

    def RecalcInvestInSubtotal(self):
        '''重算 投资流入小计'''

        ReturnFromAssets = kit.toFloatOrZero(self.tcReturnFromAssets.GetValue())
        ReturnFromInvest = kit.toFloatOrZero(self.tcReturnFromInvest.GetValue())

        InvestInSubtotal = ReturnFromAssets + ReturnFromInvest

        self.tcInvestInSubtotal.SetValue('%.0f' %(InvestInSubtotal))

    def RecalcInvestOutSubtotal(self):
        '''重算 投资流出小计'''

        PaidForAsset = kit.toFloatOrZero(self.tcPaidForAsset.GetValue())
        PaidForInvest = kit.toFloatOrZero(self.tcPaidForInvest.GetValue())

        InvestOutSubtotal = PaidForAsset + PaidForInvest

        self.tcInvestOutSubtotal.SetValue('%.0f' %(InvestOutSubtotal))

    def OnTcPaidForAssetText(self, event):
        self.RecalcInvestOutSubtotal()

    def OnTcPaidForInvestText(self, event):
        self.RecalcInvestOutSubtotal()

    def OnTcReturnFromAssetsText(self, event):
        self.RecalcInvestInSubtotal()

    def OnTcReturnFromInvestText(self, event):
        self.RecalcInvestInSubtotal()

    def OnTcInvestInSubtotalText(self, event):
        self.RecalcNetFlowInvest()
        self.RecalcCashFlowInvest()

    def OnTcInvestOutSubtotalText(self, event):
        self.RecalcNetFlowInvest()
        self.RecalcCashFlowInvest()

    

